<table border="1">
<tr>
	<th rowspan="2">NO</th>
	<th rowspan="2">Dealer</th>
	<th rowspan="2">Unit</th>
	<th colspan="2">Personal</th>
	<th rowspan="2">Harga Dealer</th>
	<th rowspan="2">Overiding</th>
	<th rowspan="2">Pph 5%</th>
	<th rowspan="2">Jumlah</th>
	<th rowspan="2">KOTA</th>
</tr>
<tr>
	<th>GROUP 10%</th>
	<th>GROUP 20%</th>
</tr>
<?php 
	$test= 0;
	$overriding = 0;
	$jumlah = 0;
	$hargadealer = 0;
	$i = 1;	
	
	$total = 0;
	$totalgroup10 = 0;
	$totalgroup20 = 0;
	$totalhargadealer = 0;
	$totaloveriding = 0;
	$totalpph = 0;
	$totaljumlah = 0;
	
	foreach($query as $row){
	if(empty($row->group10)){
			$temp10 = 0;
		}else{
			$temp10 = $row->group10;
		}
	if(empty($row->group20)){
				$temp20 = 0;
			}else{
				$temp20 = $row->group20;
			}
	if(empty($row->total_omset)){
			$test = 0;
		}else{
			$test = $row->total_omset;
		}
	
	//$test = $temp10 +$temp20;			
	//
	if( $test >= 300000){
		if(empty($row->group10downline)){
			$temp10d = 0;
		}else{
			$temp10d = $row->group10downline;
		}
			if(empty($row->group20downline)){
				$temp20d = 0;
			}else{
				$temp20d = $row->group20downline;
			}
			
		$temp = $temp10d;
		$temp2 = $temp20d;
		$hargadealer = ($temp * 0.9) + ($temp2 * 0.8);
		$overiding = $hargadealer * 0.03;
		$pph = $overiding * 0.05;
		$jumlah = $overiding - $pph;
		if($overiding != 0 ){
			echo "<tr>";
			echo "<td> ".$i++."</td>";
			echo "<td>".$row->strnama_dealer."</td>";
			echo "<td>".$row->strnama_unit."</td>";
			echo "<td>".$temp."</td>";
			echo "<td>".$temp2."</td>";
			echo "<td>".$hargadealer."</td>";
			echo "<td>".$overiding."</td>";
			echo "<td>".$pph."</td>";
			echo "<td>".$jumlah."</td>";
			echo "<td>".$row->strnama_cabang."</td>";
			echo "</tr>";
			
			$totalgroup10 = $totalgroup10 + $temp;
			$totalgroup20 = $totalgroup20 + $temp2;
			$totalhargadealer = $totalhargadealer + $hargadealer;
			$totaloveriding = $totaloveriding + $overiding;
			$totalpph = $totalpph + $pph;
			$totaljumlah = $totaljumlah + $jumlah;
			}
		}
	}
?>
<tr>
	<td colspan="3">TOTAL</td>
	<td><?php echo $totalgroup10;?></td>
	<td><?php echo $totalgroup20;?></td>
	<td><?php echo $totalhargadealer;?></td>
	<td><?php echo $totaloveriding;?></td>
	<td><?php echo $totalpph;?></td>
	<td><?php echo $totaljumlah;?></td>
</tr>
</table>
